package com.groupbuying.redpacket.service.impl;

import com.groupbuying.redpacket.utils.apiresult.ApiResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.groupbuying.redpacket.dao.ActivityThemeDao;
import com.groupbuying.redpacket.domain.ActivityThemeDO;
import com.groupbuying.redpacket.service.ActivityThemeService;


@Service
public class ActivityThemeServiceImpl implements ActivityThemeService {
    @Autowired
    private ActivityThemeDao activityThemeDao;

    @Override
    public ActivityThemeDO get(Long id) {
        return activityThemeDao.get(id);
    }

    @Override
    public List<ActivityThemeDO> list(Map<String, Object> map) {
        return activityThemeDao.list(map);
    }

    @Override
    public int count(Map<String, Object> map) {
        return activityThemeDao.count(map);
    }

    @Override
    public int save(ActivityThemeDO activityTheme) {
        return activityThemeDao.save(activityTheme);
    }

    @Override
    public int update(ActivityThemeDO activityTheme) {
        return activityThemeDao.update(activityTheme);
    }

    @Override
    public int remove(Long id) {
        return activityThemeDao.remove(id);
    }

    @Override
    public int batchRemove(Long[] ids) {
        return activityThemeDao.batchRemove(ids);
    }

    @Override
    public String getThemeName(Long id) {
        return activityThemeDao.getThemeName(id);
    }

    /**
     * 增加分类活动
     * @param activityTheme
     * @return
     */
    @Override
    public ApiResult addActivityTheme(ActivityThemeDO activityTheme) {
        try {
            if (activityTheme.getThemeName() == null) {
                return ApiResult.failure("错误提示:分类名称不可为空");
            }
            if (activityTheme.getSingleCountsLimit() == null) {
                return ApiResult.failure("错误提示:单人中奖红包个数上限不可为空");
            }
            if (activityTheme.getSingleTotalAmountLimit() == null) {
                return ApiResult.failure("错误提示:单人中奖红包金额上限不可为空");
            }
            activityTheme.setCreateTime(new Date());
            activityThemeDao.save(activityTheme);
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.failure("添加失败");
        }
        return ApiResult.success();
    }

    /**
     * 修改分类活动
     * @param activityTheme
     * @return
     */
    @Override
    public ApiResult updateActivityTheme(ActivityThemeDO activityTheme) {
        try {
            if (activityTheme.getThemeName() == null) {
                return ApiResult.failure("错误提示:分类名称不可为空");
            }
            if (activityTheme.getSingleCountsLimit() == null) {
                return ApiResult.failure("错误提示:单人中奖红包个数上限不可为空");
            }
            if (activityTheme.getSingleTotalAmountLimit() == null) {
                return ApiResult.failure("错误提示:单人中奖红包金额上限不可为空");
            }
            activityThemeDao.update(activityTheme);
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.failure("修改失败");
        }
        return ApiResult.success();
    }

    /**
     * 查询全部分类活动
     * @return
     */
    @Override
    public List<ActivityThemeDO> listActivity() {
        List<ActivityThemeDO> activityThemeDOS = activityThemeDao.listActivity();
        return activityThemeDOS;
    }
}
